# coding:utf-8

import os
from loguru import logger

# 确保 logs 文件夹存在
logs_dir = os.path.join(os.path.dirname(__file__), 'logs')
if not os.path.exists(logs_dir):
    os.makedirs(logs_dir)

logger.add(f"{logs_dir}"+"/server-info-{time:YYYY-MM-DD}", 
           filter=lambda x: "INFO" in str(x["level"]).upper(),
           format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",
           level="INFO",
           rotation="1 day",
           retention="10 day",
           compression="zip"
           )

logger.add(f"{logs_dir}"+"/server-error-{time:YYYY-MM-DD}", 
           filter=lambda x: "ERROR" in str(x["level"]).upper(),
           format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",
           level="ERROR",
           rotation="1 day",
           retention="10 day",
           compression="zip"
           )

logger.add(f"{logs_dir}"+"/server-debug-{time:YYYY-MM-DD}", 
           filter=lambda x: "DEBUG" in str(x["level"]).upper(),
           format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",
           level="DEBUG",
           rotation="1 day",
           retention="10 day",
           compression="zip"
           )